/**
 * Copyright [2019] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.dess.base.thread;

import java.util.Objects;

/**
 * @project-name:dess
 * @package-name:com.hyts.dess.base.thread
 * @author:LiBo/Alex
 * @create-date:2020-06-15 9:50
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description:
 */
public class ThreadContextHolder{

    /**
     * 创建相关的上下文操作处理器功能
     * @param name
     * @return
     */
    public static <T> ThreadContext<T> create(String name){
        return new ThreadContext<T>(name);
    }

    /**
     * 创建相关的上下文操作处理器功能
     * @param name
     * @param type
     * @return
     */
    public static <T>ThreadContext<T> create(String name,String type){
        return new ThreadContext<T>(name,type);
    }

    /**
     * 获取相关的数值
     * @param threadContext
     * @return
     */
    public static <T> T getValue(ThreadContext<T> threadContext){
        Objects.requireNonNull(threadContext,"传入的上下文的对象不允许为空!");
        return threadContext.get();
    }

    /**
     * 设置相关数值
     * @param threadContext
     * @param value
     */
    public static <T> void setValue(ThreadContext<T> threadContext,T value){
        Objects.requireNonNull(threadContext,"传入的上下文的对象不允许为空!");
        threadContext.set(value);
    }

    /**
     * 线程上下文对象操作
     */
    public static <T> void remove(ThreadContext<T> threadContext){
        threadContext.set(null);
        threadContext.remove();
    }


}
